block config
{
   // Welcome sounds and messages using Steam ID:
   // Add Steam Ids to the "es_connect_steam_db.txt"
   //	0 = Do not use		1 = Use

   es_xsetinfo xe_use_steam 1

   // Welcome sounds and messages using the player's name (not recommended):
   // Add Names to the "es_connect_name_db.txt"
   // Good for LAN use
   //	0 = Do not use		1 = Use

   es_xsetinfo xe_use_name 0

   // Welcome sounds and messages using IP Address:
   // Add IP Addresses to the "es_connect_ip_db.txt"
   //	0 = Do not use		1 = Use

   es_xsetinfo xe_use_ip 0

   // General Connection Sounds & Messages:
   //	Leaving these values at "0" disables general sounds and messages.
   //	If you choose to use a sound or message, when the player connects,
   //	the player will see the message and/or hear the sound. The message
   //	and sound will only be seen and heard by the player connecting.
   //	Use these sounds and messages for general welcoming of every player.
   //	For special messages for certain players, use Steam ID, Name, or 
   //	IP Address.

   es_xsetinfo xe_general_connect_sound "0"
   es_xsetinfo xe_general_connect_message "0"

   es_xsetinfo xe_general_disconnect_sound "0"
   es_xsetinfo xe_general_disconnect_message "0"
}
/////////////////////////////////////////////////////////////////////////
// !EDIT NOTHING BELOW THIS POINT UNLESS YOU ARE AN ADVANCED SCRIPTER! //
/////////////////////////////////////////////////////////////////////////

block load
{
   es_xdoblock connect_sounds/config
   es_xsetinfo connect_sounds_ver "1.5"
   es_xmakepublic connect_sounds_ver
   es_xsetinfo xe_download 0
   es_xsetinfo xe_tempkey 0
   es_xsetinfo xe_greet_check 0
   es_xsetinfo xe_connect_message 0
   es_xsetinfo xe_connect_sound 0
   es_xsetinfo xe_disconnect_message 0
   es_xsetinfo xe_disconnect_sound 0
   es_xsetinfo xe_exists 0
   es_xsetinfo xe_port_token 0
   es_xkeygroupcreate connect_greeted
   if (server_var(xe_use_steam) = 1) do
   {
      es_xkeygroupload connect_steam |connect_sounds
      es_xforeachkey xe_tempkey in connect_steam "es_xdoblock connect_sounds/get_downloads_steam"
   }
   if (server_var(xe_use_ip) = 1) do
   {
      es_xkeygroupload connect_ip |connect_sounds
      es_xforeachkey xe_tempkey in connect_ip "es_xdoblock connect_sounds/get_downloads_ip"
   }
   if (server_var(xe_use_name) = 1) do
   {
      es_xkeygroupload connect_name |connect_sounds
      es_xforeachkey xe_tempkey in connect_name "es_xdoblock connect_sounds/get_downloads_name"
   }
   if (server_var(xe_general_connect_sound) != 0) do
   {
      es_format xe_download "sound/%1" server_var(xe_general_connect_sound)
      es downloadable server_var(xe_download)
   }
   if (server_var(xe_general_disconnect_sound) != 0) do
   {
      es_format xe_download "sound/%1" server_var(xe_general_disconnect_sound)
      es downloadable server_var(xe_download)
   }
}

block unload
{
   if (server_var(xe_use_steam) = 1) do
   {
      es_xkeygroupdelete connect_steam
   }
   if (server_var(xe_use_ip) = 1) do
   {
      es_xkeygroupdelete connect_ip
   }
   if (server_var(xe_use_name) = 1) do
   {
      es_xkeygroupdelete connect_name
   }
   es_xkeygroupdelete connect_greeted
}

block get_downloads_steam
{
   es_keygetvalue xe_download connect_steam server_var(xe_tempkey) connect_sound
   if (server_var(xe_download) != 0) do
   {
      es_format xe_download "sound/%1" server_var(xe_download)
      es downloadable server_var(xe_download)
   }
   es_keygetvalue xe_download connect_steam server_var(xe_tempkey) disconnect_sound
   if (server_var(xe_download) != 0) do
   {
      es_format xe_download "sound/%1" server_var(xe_download)
      es downloadable server_var(xe_download)
   }
}

block get_downloads_ip
{
   es_keygetvalue xe_download connect_ip server_var(xe_tempkey) connect_sound
   if (server_var(xe_download) != 0) do
   {
      es_format xe_download "sound/%1" server_var(xe_download)
      es downloadable server_var(xe_download)
   }
   es_keygetvalue xe_download connect_ip server_var(xe_tempkey) disconnect_sound
   if (server_var(xe_download) != 0) do
   {
      es_format xe_download "sound/%1" server_var(xe_download)
      es downloadable server_var(xe_download)
   }
}

block get_downloads_name
{
   es_keygetvalue xe_download connect_name server_var(xe_tempkey) connect_sound
   if (server_var(xe_download) != 0) do
   {
      es_format xe_download "sound/%1" server_var(xe_download)
      es downloadable server_var(xe_download)
   }
   es_keygetvalue xe_download connect_name server_var(xe_tempkey) disconnect_sound
   if (server_var(xe_download) != 0) do
   {
      es_format xe_download "sound/%1" server_var(xe_download)
      es downloadable server_var(xe_download)
   }
}

event es_map_start
{
   if (server_var(xe_use_steam) = 1) do
   {
      es_xforeachkey xe_tempkey in connect_steam "es_xdoblock connect_sounds/get_downloads_steam"
   }
   if (server_var(xe_use_ip) = 1) do
   {
      es_xforeachkey xe_tempkey in connect_ip "es_xdoblock connect_sounds/get_downloads_ip"
   }
   if (server_var(xe_use_name) = 1) do
   {
      es_xforeachkey xe_tempkey in connect_name "es_xdoblock connect_sounds/get_downloads_name
   }
   if (server_var(xe_general_connect_sound) != 0) do
   {
      es_format xe_download "sound/%1" server_var(xe_general_connect_sound)
      es downloadable server_var(xe_download)
   }
   if (server_var(xe_general_disconnect_sound) != 0) do
   {
      es_format xe_download "sound/%1" server_var(xe_general_disconnect_sound)
      es downloadable server_var(xe_download)
   }
}

event player_activate
{
   if (server_var(xe_use_steam) = 1) do
   {
      es_exists xe_exists key connect_steam event_var(es_steamid)
      if (server_var(xe_exists) = 1) do
      {
         es_exists xe_exists key connect_greeted event_var(es_steamid)
         if (server_var(xe_exists) = 0) do
         {
            es_keygetvalue xe_connect_sound connect_steam event_var(es_steamid) connect_sound
            if (server_var(xe_connect_sound) != 0) then es_xdelayed 10 es_cexec_all play server_var(xe_connect_sound)
            es_keygetvalue xe_connect_message connect_steam event_var(es_steamid) connect_message
            if (server_var(xe_connect_message) != 0) then es_xdelayed 10 es_xmsg #multi server_var(xe_connect_message)
            es_keycreate connect_greeted event_var(es_steamid)
         }
      }
   }
   if (server_var(xe_use_ip) = 1) do
   {
      es_xcreateplayerlist connect_players
      es_keygetvalue xe_tempkey connect_players event_var(userid) address
      es_xkeygroupdelete connect_players
      es_token xe_port_token server_var(xe_tempkey) 2 :
      es_string xe_tempkey replace server_var(xe_port_token)
      es_xstring xe_tempkey replace :
      es_exists xe_exists key connect_ip server_var(xe_tempkey)
      if (server_var(xe_exists) = 1) do
      {
         es_exists xe_exists key connect_greeted server_var(xe_tempkey)
         if (server_var(xe_exists) = 0) do
         {
            es_keygetvalue xe_connect_sound connect_ip server_var(xe_tempkey) connect_sound
            if (server_var(xe_connect_sound) != 0) then es_xdelayed 10 es_cexec_all play server_var(xe_connect_sound)
            es_keygetvalue xe_connect_message connect_ip server_var(xe_tempkey) connect_message
            if (server_var(xe_connect_message) != 0) then es_xdelayed 10 es_xmsg #multi server_var(xe_connect_message)
            es_keycreate connect_greeted server_var(xe_tempkey)
         }
      }
   }
   if (server_var(xe_use_name) = 1) do
   {
      es_exists xe_exists key connect_name event_var(es_username)
      if (server_var(xe_exists) = 1) do
      {
         es_exists xe_exists key connect_greeted event_var(es_username)
         if (server_var(xe_exists) = 0) do
         {
            es_keygetvalue xe_connect_sound connect_name event_var(es_username) connect_sound
            if (server_var(xe_connect_sound) != 0) then es_xdelayed 10 es_cexec_all play server_var(xe_connect_sound)
            es_keygetvalue xe_connect_message connect_name event_var(es_username) connect_message
            if (server_var(xe_connect_message) != 0) then es_xdelayed 10 es_xmsg #multi server_var(xe_connect_message)
            es_keycreate connect_greeted event_var(es_username)
         }
      }
   }
   es_exists xe_exists key connect_greeted event_var(userid)
   if (server_var(xe_exists) = 0) do
   {
      if (server_var(xe_general_connect_message) != 0) then es_xdelayed 10 es_xtell event_var(userid) #multi server_var(xe_general_connect_message)
      if (server_var(xe_general_connect_sound) != 0) then es_xdelayed 10 es_xcexec event_var(userid) play server_var(xe_general_connect_sound)
      es_keycreate connect_greeted event_var(userid)
   }
}

event player_disconnect
{
   if (server_var(xe_use_steam) = 1) do
   {
      es_exists xe_exists key connect_steam event_var(es_steamid)
      if (server_var(xe_exists) = 1) do
      {
         es_keydelete connect_greeted event_var(es_steamid)
         es_keygetvalue xe_disconnect_message connect_steam event_var(es_steamid) disconnect_message
         if (server_var(xe_disconnect_message) != 0) then es_xmsg #multi server_var(xe_disconnect_message)
         es_keygetvalue xe_disconnect_sound connect_steam event_var(es_steamid) disconnect_sound
         if (server_var(xe_disconnect_sound) != 0) then es_xcexec_all play server_var(xe_disconnect_sound)
      }
   }
   if (server_var(xe_use_ip) = 1) do
   {
      es_xcreateplayerlist connect_players
      es_keygetvalue xe_tempkey connect_players event_var(userid) address
      es_xkeygroupdelete connect_players
      es_token xe_port_token server_var(xe_tempkey) 2 :
      es_string xe_tempkey replace server_var(xe_port_token)
      es_xstring xe_tempkey replace :
      es_exists xe_exists key connect_ip server_var(xe_tempkey)
      if (server_var(xe_exists) = 1) do
      {
         es_keydelete connect_greeted server_var(xe_tempkey)
         es_keygetvalue xe_disconnect_message connect_ip server_var(xe_tempkey) disconnect_message
         if (server_var(xe_disconnect_message) != 0) then es_xmsg #multi server_var(xe_disconnect_message)
         es_keygetvalue xe_disconnect_sound connect_ip server_var(xe_tempkey) disconnect_sound
         if (server_var(xe_disconnect_sound) != 0) then es_xcexec_all play server_var(xe_disconnect_sound)
      }
   }
   if (server_var(xe_use_name) = 1) do
   {
      es_exists xe_exists key connect_name event_var(es_username)
      if (server_var(xe_exists) = 1) do
      {
         es_keydelete connect_greeted event_var(es_username)
         es_keygetvalue xe_disconnect_message connect_name event_var(es_username) disconnect_message
         if (server_var(xe_disconnect_message) != 0) then es_xmsg #multi server_var(xe_disconnect_message)
         es_keygetvalue xe_disconnect_sound connect_name event_var(es_username) disconnect_sound
         if (server_var(xe_disconnect_sound) != 0) then es_xcexec_all play server_var(xe_disconnect_sound)
      }
   }
   if (server_var(xe_general_disconnect_message) != 0) then es_xdelayed 10 es_xtell event_var(userid) #multi server_var(xe_general_disconnect_message)
   if (server_var(xe_general_disconnect_sound) != 0) then es_xdelayed 10 es_xcexec event_var(userid) play server_var(xe_general_disconnect_sound)
   es_keydelete connect_greeted event_var(userid)
}